var t = require("./local"),
  e = [0, 15, 30, 90, 240, 360, 600, 1200, 2400, 3200, 4800, 7200];
module.exports = {
  saveTimes: function (e, n) {
    var a,
      l = t.getLocal(e);
    (a = "" === l || null === l ? n : l + "_" + n), t.setLocal(e, a);
  },
  isLmitByTimes: function (e) {
    var n = t.getLocal(e);
    return "" !== n && null !== n && n.toString().split("_").length > 30;
  },
  isLimitByHalfHour: function (e) {
    var n = t.getLocal(e);
    if ("" === n || null === n) return !1;
    var a = n.split("_"),
      l = new Date().getTime();
    return Math.abs(l - a[a.length - 1]) <= 18e5;
  },
  saveFaild: function (n) {
    var a = t.getLocal(n);
    "" === a || null == a ? (a = 1) : (a++, (a = Math.min(a, e.length - 1))),
      t.setLocal(n, a);
  },
  isLimitByFaild: function (n, a) {
    var l = t.getLocal(a);
    if ("" === l || null === l) return !1;
    var r = l.toString().split("_"),
      i = t.getLocal(n);
    if ("" === i || null === i || i <= 1) return !1;
    var u = (function (t, e) {
        switch (arguments.length) {
          case 1:
            return parseInt(Math.random() * t + 1, 10);
          case 2:
            return parseInt(Math.random() * (e - t + 1) + t, 10);
          default:
            return 0;
        }
      })(Math.max(0, e[i - 1]), Math.min(e[i], e[e.length - 1])),
      o = new Date().getTime();
    return Math.abs(o - r[r.length - 1]) <= 1e3 * u;
  },
  delByKey: function (e) {
    t.delLocal(e);
  },
};
